package com.mtz.handler;

import com.mtz.VO.ResultVO;
import com.mtz.exception.MtzException;
import com.mtz.utils.ResultVOUtil;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

/**
 * @author 煜赜
 * @date 2018/11/27 0027 上午 10:29
 */
@ControllerAdvice
public class MtzExceptionHandler {

    @ExceptionHandler(value = MtzException.class)
    @ResponseBody
    /** 更改返回的状态码. */
    @ResponseStatus(HttpStatus.ACCEPTED)
    public ResultVO handlerMtzException(MtzException e) {
        return ResultVOUtil.error(e.getCode(), e.getMessage());
    }
}
